
power = 5
limit = 1
while True:
    if limit * (9**power) < 10**(limit-1):
        break
    else:
        limit += 1

s = 0
for i in range(2, (9**power) * (limit-1)):
    if i == sum(map(lambda x: int(x)**power, str(i))):
        s += i

print s
